package com.yanyilu.jianjian.common;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;

/**
 * 统一响应结果集
 * @author:wangchao
 */
@JsonSerialize(include= JsonSerialize.Inclusion.NON_NULL)
@Data
public class Result<T> {

    //操作代码
    int code;

    //提示信息
    String msg;

    //结果数据
    T data;
    //结果数量
    Long count;
    //token
    String token;

    public Result(ResultCode resultCode){
        this.code = resultCode.code();
        this.msg = resultCode.msg();
    }

    public Result(ResultCode resultCode, T data){
        this.code = resultCode.code();
        this.msg = resultCode.msg();
        this.data = data;
    }

    public Result(ResultCode resultCode, T data, String token) {
        this.code = resultCode.code();
        this.msg = resultCode.msg();
        this.data = data;
        this.token = token;
    }

    public Result(ResultCode resultCode, T data, Long count) {
        this.code = resultCode.code();
        this.msg = resultCode.msg();
        this.data = data;
        this.count = count;
    }

    public Result(String msg){
        this.msg = msg;
    }
    public Result(int code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public static Result SUCCESS(){
        return new Result(ResultCode.SUCCESS);
    }

    public static <T> Result SUCCESS(T data){
        return new Result(ResultCode.SUCCESS, data);
    }

    public static <T> Result SUCCESS(T data, String token){
        return new Result(ResultCode.SUCCESS, data, token);
    }

    public static <T> Result SUCCESS(T data, Long count){
        return new Result(ResultCode.SUCCESS, data, count);
    }

    public static Result FAIL(){
        return new Result(ResultCode.FAIL);
    }

    public static Result FAIL(String msg){
        return new Result(msg);
    }

    public static Result SYSTEM_INNER_ERROR(){
        return new Result(ResultCode.SYSTEM_INNER_ERROR);
    }
    public static Result PARAM_NOT_COMPLETE(){
        return new Result(ResultCode.PARAM_NOT_COMPLETE);
    }
    public static Result USER_LOGIN_ERROR(){
        return new Result(ResultCode.USER_LOGIN_ERROR);
    }
}